export default function(Vue, options) {

  function getFormData(formData) {
    let data = ''
    for (let key in formData) {
      data += '&' + key + '=' + encodeURIComponent(formData[key] instanceof Object ? JSON.stringify(formData[key]) : formData[key])
    }
    return data.substring(1)
  }

  var params = {} //url参数列表
  window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
    params[key] = decodeURI(value)
  })
  var getToken = params.access_token
  let inApp = !!getToken
  var INTERFACE_HOST = 'http://www.hncwaxxkj.cn:9001' //本地调试 使用mock搭建静态数据服务
  var isIos = /ipod|ipad|iphone|mac os x/i.test(navigator.userAgent)

  Date.prototype.format = function(format) {
    var o = {
      'M+': this.getMonth() + 1, //month
      'd+': this.getDate(), //day
      'h+': this.getHours(), //hour
      'm+': this.getMinutes(), //minute
      's+': this.getSeconds(), //second
      'q+': Math.floor((this.getMonth() + 3) / 3), //quarter
      'S': this.getMilliseconds() //millisecond
    }

    if (/(y+)/i.test(format)) {
      format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
    }

    for (var k in o) {
      if (new RegExp('(' + k + ')').test(format)) {
        format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
      }
    }
    return format
  }
  Vue.$AppConfig = Object.assign({
    urlParams: params,
    inApp: inApp,
    isIos: isIos,
    INTERFACE_HOST: INTERFACE_HOST,
    getToken: getToken,
    getFormData: getFormData,
    appJSBridge: function(key, message) {
      if (typeof (window.JsBridge) == 'object' && typeof (window.JsBridge[key]) == 'function') {
        message == undefined ? window.JsBridge[key]() : window.JsBridge[key](message)
        return true
      } else if (typeof (window.webkit) == 'object') {
        try {
          message == undefined ? window.webkit.messageHandlers[key].postMessage('') : window.webkit.messageHandlers[key].postMessage(message)
          return true
        } catch (e) {
          console.log(e)
          return false
        }
      } else {
        return false
      }

    }
  }, typeof options === 'function' ? options() : options)

}
